﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using myFinance.Domain;
using myFinance.Utils;
namespace myFinance.Services {
    public class CategoryService : ICategoryService  {
         ICategoryRepository _repository = null;
        /// <summary>
         /// Creates a CategoryService based on the passed-in repository
        /// </summary>
         /// <param name="repository">An ICategoryRepository</param>
         public CategoryService(ICategoryRepository repository) {
            _repository = repository;
            if (_repository == null)
                throw new InvalidOperationException("Repository cannot be null");
        }

        public PagedList<Category> GetCategories(int pageIndex,int pageSize) { 
            return _repository.GetCategories().ToPagedList<Category>(pageIndex, pageSize); 
        }
        public void Save(Category category)
        {
            _repository.Save(category);
        }
        public Category Read(int id) {
          return  _repository.Read(id);
        }
        public void Delete(int id) {
            _repository.Delete(id);
        }
    }
}
